home *** CD-ROM | disk | FTP | other *** search
- #define BASE_RES_ID 400
- #define NIL_POINTER 0L
- #define MOVE_TO_FRONT -1L
- #define REMOVE_ALL_EVENTS 0
- #define SCROLL_BAR_PIXELS 16
- #define DRAG_THRESHOLD 30
- #define NIL_ACTION_PROC NIL_POINTER
-
- #define MIN_SLEEP 0L
- #define NIL_MOUSE_REGION 0L
-
- #define WNE_TRAP_NUM 0x60
- #define UNIMPL_TRAP_NUM 0x9F
-
- #define ERROR_ALERT_ID BASE_RES_ID+1
- #define NO_WIND BASE_RES_ID
- #define NO_PICTS BASE_RES_ID+1
- #define CANT_LOAD_PICT BASE_RES_ID+2
-
- #define NIL_STRING "\p"
- #define NIL_TITLE NIL_STRING
- #define VISIBLE TRUE
- #define START_VALUE 1
- #define MIN_VALUE 1
- #define NIL_REF_CON NIL_POINTER
- #define HOPELESSLY_FATAL_ERROR "\pGame over, man!"
-
- WindowPtr gPictWindow;
- ControlHandle gScrollBarHandle;
- Boolean gDone, gWNEImplemented;
- EventRecord gTheEvent;
- Rect gDragRect;
-
- pascal void ScrollProc();
-
- /******************************** main *********/
-
- main()
- {
- ToolBoxInit();
- WindowInit();
- SetUpDragRect();
- SetUpScrollBar();
- MainLoop();
- }
-
- /*********************************** ToolBoxInit */
-
- ToolBoxInit()
- {
- InitGraf( &thePort );
- InitFonts();
- FlushEvents( everyEvent, REMOVE_ALL_EVENTS );
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( NIL_POINTER );
- InitCursor();
- }
-
- /******************************** WindowInit *********/
-
- WindowInit()
- {
- if ( ( gPictWindow = GetNewWindow( BASE_RES_ID, NIL_POINTER, MOVE_TO_FRONT ) ) == NIL_POINTER )
- ErrorHandler( NO_WIND );
-
- SelectWindow( gPictWindow );
- ShowWindow( gPictWindow );
- SetPort( gPictWindow );
- }
-
- /******************************** SetUpDragRect *********/
-
- SetUpDragRect()
- {
- gDragRect = screenBits.bounds;
- gDragRect.left += DRAG_THRESHOLD;
- gDragRect.right -= DRAG_THRESHOLD;
- gDragRect.bottom -= DRAG_THRESHOLD;
- }
-
- /********************************** SetUpScrollBar *******/
-
- SetUpScrollBar()
- {
- Rect vScrollRect;
- int numPictures;
-
- if ( ( numPictures = CountResources( 'PICT' ) ) <= 0 )
- ErrorHandler( NO_PICTS );
-
- vScrollRect = gPictWindow->portRect;
- vScrollRect.top -= 1;
- vScrollRect.bottom += 1;
- vScrollRect.left = vScrollRect.right - SCROLL_BAR_PIXELS+1;
- vScrollRect.bottom += 1;
- gScrollBarHandle = NewControl( gPictWindow, &vScrollRect, NIL_TITLE, VISIBLE, START_VALUE, MIN_VALUE, numPictures, scrollBarProc, NIL_REF_CON );
- }
-
- /******************************** MainLoop *********/
-
- MainLoop()
- {
- gDone = FALSE;
- gWNEImplemented = ( NGetTrapAddress( WNE_TRAP_NUM, ToolTrap ) != NGetTrapAddress( UNIMPL_TRAP_NUM, ToolTrap ) );
- while ( gDone == FALSE )
- {
- HandleEvent();
- }
- }
-
- /************************************* HandleEvent */
-
- HandleEvent()
- {
- if ( gWNEImplemented )
- WaitNextEvent( everyEvent, &gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION );
- else
- {
- SystemTask();
- GetNextEvent( everyEvent, &gTheEvent );
- }
-
- switch ( gTheEvent.what )
- {
- case mouseDown:
- HandleMouseDown();
- break;
- case updateEvt:
- BeginUpdate( gTheEvent.message );
- DrawControls( gTheEvent.message );
- UpdateMyWindow( gTheEvent.message );
- EndUpdate( gTheEvent.message );
- break;
- }
- }
-
- /************************************* HandleMouseDown */
-
- HandleMouseDown()
- {
- WindowPtr whichWindow;
- short int thePart;
- Point thePoint;
- ControlHandle theControl;
-
- thePart = FindWindow( gTheEvent.where, &whichWindow );
-
- switch( thePart )
- {
- case inSysWindow:
- SystemClick( &gTheEvent, whichWindow );
- break;
- case inDrag:
- DragWindow( whichWindow, gTheEvent.where, &gDragRect );
- break;
- case inContent:
- thePoint = gTheEvent.where;
- GlobalToLocal( &(thePoint) );
- thePart = FindControl( thePoint, whichWindow, &theControl );
-
- if ( theControl == gScrollBarHandle )
- {
- if ( thePart == inThumb )
- {
- thePart = TrackControl( theControl, thePoint, NIL_ACTION_PROC );
- UpdateMyWindow( whichWindow );
- }
- else
- {
- thePart = TrackControl( theControl, thePoint, &ScrollProc );
- UpdateMyWindow( whichWindow );
- }
- }
- break;
- case inGoAway:
- gDone = TRUE;
- break;
- }
- }
-
- /********************************** ScrollProc *******/
-
- pascal void ScrollProc(theControl, theCode)
-
- ControlHandle theControl;
- int theCode;
-
- {
- int curControlValue, maxControlValue, minControlValue;
-
- maxControlValue = GetCtlMax( theControl );
- curControlValue = GetCtlValue( theControl );
- minControlValue = GetCtlMin( theControl );
-
- switch ( theCode )
- {
- case inPageDown:
- case inDownButton:
- if ( curControlValue < maxControlValue )
- {
- curControlValue += 1;
- }
- break;
- case inPageUp:
- case inUpButton:
- if ( curControlValue > minControlValue );
- {
- curControlValue -= 1;
- }
- }
-
- SetCtlValue( theControl, curControlValue );
- }
-
- /********************************** UpdateMyWindow *******/
-
- UpdateMyWindow( drawingWindow )
-
- WindowPtr drawingWindow;
-
- {
- PicHandle currentPicture;
- Rect drawingClipRect, myRect;
- RgnHandle tempRgn;
-
- tempRgn = NewRgn();
- GetClip( tempRgn );
-
- myRect = drawingWindow->portRect;
- myRect.right -= SCROLL_BAR_PIXELS;
- EraseRect( &myRect );
-
- currentPicture = (PicHandle)GetIndResource( 'PICT', GetCtlValue( gScrollBarHandle ) );
-
- if ( currentPicture == NIL_POINTER )
- ErrorHandler( CANT_LOAD_PICT );
-
- CenterPict( currentPicture, &myRect );
-
- drawingClipRect = drawingWindow->portRect;
- drawingClipRect.right -= SCROLL_BAR_PIXELS;
- ClipRect( &drawingClipRect );
-
- DrawPicture( currentPicture, &myRect );
-
- SetClip( tempRgn );
- DisposeRgn( tempRgn );
- }
-
- /******************************** CenterPict *********/
-
- CenterPict( thePicture, myRectPtr )
-
- PicHandle thePicture;
- Rect *myRectPtr;
-
- {
- Rect windRect, pictureRect;
-
- windRect = *myRectPtr;
- pictureRect = (**( thePicture )).picFrame;
- myRectPtr->top = (windRect.bottom - windRect.top - (pictureRect.bottom - pictureRect.top)) / 2 + windRect.top;
- myRectPtr->bottom = myRectPtr->top + (pictureRect.bottom - pictureRect.top);
- myRectPtr->left = (windRect.right - windRect.left - (pictureRect.right - pictureRect.left)) / 2 + windRect.left;
- myRectPtr->right = myRectPtr->left + (pictureRect.right - pictureRect.left);
- }
-
- /******************************** ErrorHandler *********/
-
- ErrorHandler( stringNum )
-
- int stringNum;
-
- {
- StringHandle errorStringH;
-
- if ( ( errorStringH = GetString( stringNum ) ) == NIL_POINTER )
- ParamText( HOPELESSLY_FATAL_ERROR, NIL_STRING, NIL_STRING, NIL_STRING );
-
- else
- {
- HLock( errorStringH );
- ParamText( *errorStringH, NIL_STRING, NIL_STRING, NIL_STRING );
- HUnlock( errorStringH );
- }
-
- StopAlert( ERROR_ALERT_ID, NIL_POINTER );
- ExitToShell();
- }